using AccessingEmbeddedResource.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace AccessingEmbeddedResource.ViewModels;

[ObservableObject]
public partial class MainPageViewModel {
    private readonly IBackgroundService _backgroundService;

    public MainPageViewModel(IBackgroundService backgroundService) {
        _backgroundService = backgroundService ??
            throw new ArgumentNullException(nameof(backgroundService));
    }

    [ObservableProperty] private ImageSource _backgroundImageSource;

    [RelayCommand]
    private async Task LoadBackgroundImage() {
        var bytes = await _backgroundService.GetBackgroundImage();
        BackgroundImageSource =
            ImageSource.FromStream(() => new MemoryStream(bytes));
    }
}